//
//  WYTabBarView.swift
//  weibo
//
//  Created by 王玉东 on 16/4/6.
//  Copyright © 2016年 wyd. All rights reserved.
//

import UIKit

class WYTabBarView: UITabBar {
    
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        addSubview(centerBtn)
    
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        
        super.layoutSubviews() //必须调用
        
        let subItemW:CGFloat = self.frame.width / 5
        
        let subItemH:CGFloat = self.frame.height
        
        //let subItemX:CGFloat = 0
        
        let subItemY:CGFloat = 0
        
        var index:CGFloat = 0
        
        for item in subviews {
        
            if item.isKindOfClass(NSClassFromString("UITabBarButton")!) {
            
            item.frame = CGRectMake(index * subItemW, subItemY, subItemW, subItemH)
            
            index += (index == 1) ? 2 : 1
            }
           
        }
        
        centerBtn.frame = CGRectMake(2 * subItemW, subItemY, subItemW, subItemH)
    
    }
    

    //创建btn
    lazy var centerBtn: UIButton = {
    
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button"),forState:.Normal)
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), forState:.Highlighted )
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState:.Highlighted )
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        
        return btn

    }()
    
    //设置button
//    func CenterBtn() -> UIButton {
//    
//
//    }
    
    

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */

}
